//
//  UCCoordinateBounds.m
//  AeroMapSDK
//
//  Created by 北京国泰北斗科技有限公司 on 2017/3/22.
//  Copyright © 2017年 北京国泰北斗科技有限公司. All rights reserved.
//

#import "UCCoordinateBounds.h"
#import <GoogleMaps/GoogleMaps.h>
#import "UCPath.h"
#import "UCMapView.h"

@interface UCCoordinateBounds()

@property(nonatomic,strong)GMSCoordinateBounds *gmBounds;
@end

@implementation UCCoordinateBounds

- (instancetype)initWithPath:(UCPath *)path{
    self = [super init];
    if (self) {
        self.gmBounds = [[GMSCoordinateBounds alloc] initWithPath:[path valueForKey:@"gmPath"]];
    }
    return self;
}
- (instancetype)initWithCoordinate:(CLLocationCoordinate2D)coord1
                        coordinate:(CLLocationCoordinate2D)coord2{
    self = [super init];
    if (self) {
        self.gmBounds = [[GMSCoordinateBounds alloc] initWithCoordinate:coord1 coordinate:coord2];
        
    }
    return self;
}

- (instancetype)initWithVisibleBoundsWithMap:(UCMapView *)mapView{
    self = [super init];
    if (self) {
        GMSMapView *map = [mapView valueForKey:@"map"];
        GMSVisibleRegion region = [map.projection visibleRegion];
        self.gmBounds = [[GMSCoordinateBounds alloc] initWithRegion:region];
    }
    return self;
}

- (UCCoordinateBounds *)includingCoordinate:(CLLocationCoordinate2D)coordinate{

    _gmBounds = [_gmBounds includingCoordinate:coordinate];
    return self;
}


- (UCCoordinateBounds *)includingBounds:(UCCoordinateBounds *)other{

    _gmBounds = [_gmBounds includingBounds:other.gmBounds];
    return self;
}


- (BOOL)containsCoordinate:(CLLocationCoordinate2D)coordinate{

    BOOL result = [_gmBounds containsCoordinate:coordinate];
    return result;
}


- (BOOL)intersectsBounds:(UCCoordinateBounds *)other{

    return [_gmBounds intersectsBounds:other.gmBounds];
}
@end
